package com.tanhua.sso.controller;

import com.tanhua.sso.service.HuanXinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("user/huanxin")
public class HuanXinController {

    @Autowired
    private HuanXinService huanXinService;

    /**
     * 添加联系人
     */
    @PostMapping("contacts/{userId}/{friendId}")
    public ResponseEntity<Void> contactUsers(@PathVariable("userId") Long userId,
                                             @PathVariable("friendId") Long friendId) throws IOException {
        boolean result = this.huanXinService.contactUsers(userId, friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 发送系统消息
     */
    @PostMapping("messages")
    public ResponseEntity<Void> sendMsg(@RequestParam("target") String target,
                                        @RequestParam("msg") String msg,
                                        @RequestParam(value = "type", defaultValue = "txt") String type) throws Exception {
        this.huanXinService.sendMsg(target, type, msg);
        return ResponseEntity.ok(null);
    }
}
